using Admin2025.Application.Dtos;
using Admin2025.Application.Services;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Threading.Tasks;

namespace Admin2025.Api.Controllers;

[ApiController]
[Route("api/[controller]")]
public class RoleController : ControllerBase
{
    private readonly IAppRoleService _service;
    public RoleController(IAppRoleService service)
    {
        _service = service;
    }

    [HttpPost]
    public async Task<IActionResult> Create([FromBody] CreateRoleDto dto)
    {
        var result = await _service.CreateRoleAsync(dto);
        return Ok(result);
    }

    [HttpDelete("{id}")]
    public async Task<IActionResult> Delete(Guid id)
    {
        var result = await _service.DeleteRoleAsync(id);
        return Ok(result);
    }

    [HttpPut("{id}")]
    public async Task<IActionResult> Update(Guid id, [FromBody] UpdateRoleDto dto)
    {
        var result = await _service.UpdateRoleAsync(id, dto);
        return Ok(result);
    }

    [HttpPost("{id}/enable")]
    public async Task<IActionResult> Enable(Guid id)
    {
        var result = await _service.EnableRole(id);
        return Ok(result);
    }

    [HttpPost("{id}/disable")]
    public async Task<IActionResult> Disable(Guid id)
    {
        var result = await _service.DisableRole(id);
        return Ok(result);
    }

    [HttpPost("{id}/assign-permission")]
    public async Task<IActionResult> AssignPermission(Guid id, [FromBody] AssignPermissionDto dto)
    {
        var result = await _service.AssignPermission(id, dto.PermissionCode);
        return Ok(result);
    }

    [HttpPost("{id}/remove-permission")]
    public async Task<IActionResult> RemovePermission(Guid id, [FromBody] AssignPermissionDto dto)
    {
        var result = await _service.RemovePermission(id, dto.PermissionCode);
        return Ok(result);
    }
}
